package org.example.timer.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
public class TimerTest {
    public static void main(String args[]) throws Exception{

        log.info("主线程号：" + Thread.currentThread().getId());
        BlockingQueue queue = new BlockingQueue(3);
        ThreadPool threadPool = new ThreadPool(2, queue, new ThreadPool.RejectPolicy<Runnable>() {
            @Override
            public void reject(BlockingQueue<Runnable> queue, Runnable task) {
                // 拒绝之后，由主线程来操作
                task.run();
            }
        });
        AtomicInteger counter = new AtomicInteger(0);
        for (int i = 0; i < 10; i++) {
            threadPool.execute(() -> {
                log.info(counter.getAndIncrement() + "  执行此任务的线程号:" + Thread.currentThread().getId());
            });
        }

        System.out.println(((int)'0'));

        Thread.sleep(Integer.MAX_VALUE);
    }
}
